import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 复检类型信息 */
export interface RecheckCategory {
  id: number // 复检类型id
  status?: number // 启用状态，1，启用；0，禁用
  code: string // 编码
  name?: string // 名称
  recheckPeriod?: number // 复检周期
  description: string // 备注
}

/** 复检类型与复检项关联信息 */
export interface RecheckCategory2Item {
  id?: number // 主键
  categoryId: number // 复检类型ID
  categoryName?: string // 复检类型名称
  itemId: number // 复检项ID
  itemName?: string // 复检项名称
}

// 复检类型 API
export const RecheckCategoryApi = {
  // 查询已绑定复检类型项目
  getItemsByCatId: async (catId: number) => {
    return await request.get({ url: `/mold/recheck-cat2item/list-catid?catId=` + catId })
  },

  // 批量创建复检类型与复检项的关联
  batchCreateRecheckCat2item: async (data: RecheckCategory2Item[]) => {
    return await request.post({ url: `/mold/recheck-cat2item/update-catid`, data })
  },

  // 删除指定保养类型的关联项
  deleteByCategoryId: async (catId: number) => {
    return await request.delete({
      url: `/mold/recheck-cat2item/delete-catid?catId=` + catId
    })
  },

  // 查询复检类型列表
  getRecheckCategoryAll: async () => {
    return await request.get({ url: `/mold/recheck-category/all` })
  },

  // 查询复检类型分页
  getRecheckCategoryPage: async (params: any) => {
    return await request.get({ url: `/mold/recheck-category/page`, params })
  },

  // 查询复检类型详情
  getRecheckCategory: async (id: number) => {
    return await request.get({ url: `/mold/recheck-category/get?id=` + id })
  },

  // 新增复检类型
  createRecheckCategory: async (data: RecheckCategory) => {
    return await request.post({ url: `/mold/recheck-category/create`, data })
  },

  // 修改复检类型
  updateRecheckCategory: async (data: RecheckCategory) => {
    return await request.put({ url: `/mold/recheck-category/update`, data })
  },

  // 删除复检类型
  deleteRecheckCategory: async (id: number) => {
    return await request.delete({ url: `/mold/recheck-category/delete?id=` + id })
  },

  /** 批量删除复检类型 */
  deleteRecheckCategoryList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/recheck-category/delete-list?ids=${ids.join(',')}` })
  },

  // 导出复检类型 Excel
  exportRecheckCategory: async (params) => {
    return await request.download({ url: `/mold/recheck-category/export-excel`, params })
  },

  // 下载导入模板
  importTemplate: async () => {
    return request.download({ url: '/mold/recheck-category/get-import-template' })
  }
}
